package com.tcm.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tcm.config.AppProperties;
import com.tcm.entity.Code;
import com.tcm.entity.dto.CodeUpdateDto;
import com.tcm.entity.resp.PageR;
import com.tcm.entity.vo.CodeTypeResult;
import com.tcm.exception.DatabaseOperationException;
import com.tcm.exception.EntityAlreadyExistException;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Guqier
 * @version 1.0
 * @date 2023/7/2 17:06
 */
public interface CodeService extends IService<Code> {
    @Cacheable(value = AppProperties.ENTITY_CACHE_CODE, key = "#id", unless = "#result == null")
    Code getCodeById(Long id);

    @CacheEvict(value = AppProperties.ENTITY_CACHE_CODE, key = "#id", condition = "#id != null")
    boolean removeCodeById(Long id);

    @CacheEvict(value = AppProperties.ENTITY_CACHE_CODE, key = "#code.id", condition = "#code.id != null")
    boolean updateCodeById(Code code);

    List<CodeTypeResult> getCodeType();

    @Transactional
    boolean addCode(CodeUpdateDto codeUpdateDto, Long currUserId) throws EntityAlreadyExistException;

    PageR<CodeUpdateDto> getCodeListByPage(Integer pageNum, Integer pageSize, String type);

    @Transactional
    boolean dropCodeByIds(List<Long> ids, Long currUserId) throws DatabaseOperationException;

    @Transactional
    boolean modifyCode(CodeUpdateDto codeUpdateDto, Long currUserId);

    List<Code> getGradeList();
}
